package com.sandalov.freesms;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class FreeSMS extends Activity {
	/** Called when the activity is first created. */ 

    ImageView imView;
    String imageUrl="http://www.google.ru/images/logos/ps_logo2.png";    
     
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
       
        Button bt3= (Button)findViewById(R.id.get_imagebt);
        bt3.setOnClickListener(getImgListener);
        imView = (ImageView)findViewById(R.id.imview);
    }    

    View.OnClickListener getImgListener = new View.OnClickListener()
    {
          public void onClick(View view) {
               // TODO Auto-generated method stub               
               downloadFile(imageUrl/*+"png"+i+".png"*/);
          }     
    };
   
    Bitmap bmImg;
    void downloadFile(String fileUrl){
          URL myFileUrl =null;          
          try {
               myFileUrl= new URL(fileUrl);
          } catch (MalformedURLException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          }
          try {
               HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
               conn.setDoInput(true);
               conn.connect();
               InputStream is = conn.getInputStream();
               
               bmImg = BitmapFactory.decodeStream(is);
               imView.setImageBitmap(bmImg);
          } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          }
     }
}

//package com.sandalov.freesms;
//
//import android.app.Activity;
//import android.os.Bundle;
//
//
//public class FreeSMS extends Activity {
//    /** Called when the activity is first created. */
//    @Override
//    public void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.main);
//    }    
//}